function a = extendArray(a, b, arrayType)
  % "Intelligently" extend a (1-D) array, i.e., given 1-D input arrays a and 
  % (optionally) b, either or both of which may be a scalar (i.e., a one-element 
  % array) append b to a.  Optional argument arrayType facilitates resolution of
  % ambiguity and more self-documenting calling routines.
  %
  % Author: David Goldsmith, Wash. State Dept. of Ecology, dgol461@ecy.wa.gov
  % Release date: 9/15/2011

    if nargin < 3
        if isnumeric(a)
            arrayType = 'n';
        elseif ischar(a)
            arrayType = 'h';
        elseif iscell(a)
            arrayType = 'c';
        elseif isstruct(a)
            arrayType = 's';
        else
            arrayType = 'o';
        end
    end
    
    if nargin < 2
        switch arrayType
            case 'n'
                b = [];
            case 'h'
                b = '';
            case 'c'
                b = {};
            case 's'
                b = struct;
            case 'o'
                b = a.empty;
        end
    end    

    try
        m = length(b);
        switch arrayType
            case {'n', 'h'}
                a(end+1:end+m) = b;
            case 'c'
                for i=1:m
                    a{end+1} = b{i};
                end
            case 's'
                n = length(a);
                for i=1:m
                    for field=fieldnames(b(i))'
                        field = field{:};
                        a(n+i).(field) = b(i).(field);
                    end
                end
            case 'o'
                n = length(a);
                iprops = properties(b);
                for i=1:m
                    for prop=iprops'
                        prop = prop{:}
                        if any(isproperty(a, prop))
                            a(n+i).(prop) = b(i).(prop);
                        end
                    end
                end
        end
    catch ME
        getReport(ME)
%        uiwait
        return
    end
end